<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    

<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/maintable.css"></link>

</head>
	<script>
		//查看一级分类下是否有小分类
		function checkHaveNext(e){
			var has=true;
			$.ajax({
				type:"POST",
				url:"CateServlet.do",
				data:{flog:"checkHaveNext",parentId:e},
				async:false,
				success:function(o){
					if(o=="0"){
						alert("该一级分类下还有小分类或商品，不能删除");
						has=false;
					}
				}
			});
			return has;
		}
		
		//查看二级分类下有没有商品
		function checkHaveGoods(e){
			var has=true;
			$.ajax({
				type:"POST",
				url:"CateServlet.do",
				data:{flog:"checkHaveGoods",id:e},
				async:false,
				success:function(o){
					if(o=="0"){
						alert("该分类下还有商品，不能删除");
						has=false;
					}
				}
			});
			return has;
		}
		//
		function del(e){
			var ok=true;
			if(checkHaveNext(e)==false){
				ok=false;
			}
			if(ok==true){
				return confirm("确认删除吗？");
			}
			return ok;
		}
		//
		function delSmall(e){
			var ok=true;
			if(checkHaveGoods(e)==false){
				ok=false;
			}
			if(ok==true){
				return confirm("确认删除吗？");
			}
			return ok;
		}
	</script>

<body>
	<div class="div_title">
		<div class="div_titlename">
			<img src="images/san_jiao.gif"><span>商品维护 分类管理</span>
		</div>
	</div>
	
	<table class="main_table">
		<tr>
			<td colspan=2>一级分类</td>
			<td colspan=2>二级分类</td>
		</tr>
		<c:forEach var="bigcate" items="${bigCateList }">
			<tr >
				<td>${bigcate.cateName}</td>
				<td>
					<a href="CateServlet.do?flog=goChangeBigCate&id=${bigcate.id }">修改</a>|
					<a href="CateServlet.do?flog=delCate&id=${bigcate.id }" onclick="return del(${bigcate.id })">删除</a>
				</td>
				<td>
					<c:forEach var="smallcate" items="${cateList}">
						<c:if test="${smallcate.parentId==bigcate.id }">
							${smallcate.cateName }<br/>
						</c:if>
					</c:forEach>
				</td>
				<td>
					<c:forEach var="smallcate" items="${cateList}">
						<c:if test="${smallcate.parentId==bigcate.id }">
							<a href="CateServlet.do?flog=goChangeSmallCate&id=${smallcate.id }">修改</a>|
							<a href="CateServlet.do?flog=delCate&id=${smallcate.id }" onclick="return delSmall(${smallcate.id})">删除</a><br/>
						</c:if>
					</c:forEach>
				</td>
			</tr>
		</c:forEach>
	</table>
	${msg }
</body>
</html>	
